package parser;

import java.io.File;
import java.util.List;

public class ReuterParser {
	
	private String sgmDirectory;
	private String trainingFileName;
	private String testingFileName;
	private double trainingRatio;
	private List<String> labels;
	
	public void setSgmDirectory(String directory) {
		sgmDirectory = directory;
	}
	
	public void setTrainingFileName(String filename) {
		trainingFileName = filename;
	}
	
	public void setTestingFileName(String filename) {
		testingFileName = filename;
	}
	
	public void setTrainingRatio(double ratio) {
		trainingRatio = ratio;
	}
	
	public void setLabels(List<String> labels) {
		this.labels = labels;
	}
	
	public void run() {
		FileParser parser = new FileParser();
		
		// Get list of files in SGM directory
		File in_dir = new File(sgmDirectory);
		File[] files = in_dir.listFiles();
		
		for(int i = 0; i < files.length; ++i) {
			if (files[i].getName().endsWith(".sgm")) {
				parser.run(sgmDirectory + files[i].getName());
			}
		}
		
		// Skip useless articles
		parser.drop_useless_articles();
		
		// Save articles to new files, training and testing
		int mid = (int)((double) parser.size() * trainingRatio);
		parser.save_articles(trainingFileName, labels, 1, mid);
		parser.save_articles(testingFileName, labels, mid + 1, parser.size());
	}
}



/*
 * 
 * 		FileParser parser = new FileParser();
		//parser.run("/home/discovery/pl/ksr_1/reuters21578/reut2-021.sgm");
		
		File in_dir = new File(raw_articles_dir);
		File[] files = in_dir.listFiles();
		
		for (int i = 0; i < files.length; ++i) {
			if (files[i].getName().endsWith(".sgm")) {
		//		System.out.println(files[i].getName());
		//		parser.run(raw_articles_dir + files[i].getName());
			}
		}
		
		//parser.drop_useless_articles();
		//parser.save_articles(xml_articles_file, labels_to_save);
 * 
 */
